package com.heisen.fileapi.service;

import com.heisen.base.entity.Api;
import com.heisen.fileapi.dto.FileDto;
import com.heisen.fileapi.service.fallback.FileServiceFallback;
import feign.Response;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;
import java.util.List;

/**
 * @author sen
 * @description
 * @date 2023/12/18 17:22
 */
@FeignClient(value = "file", contextId = "fileClient", fallbackFactory = FileServiceFallback.class)
public interface FileService {



    /**
     *   上传照片
     * @param files  文件
     * @return
     */
    @PostMapping("/file/uploadFile")
    Api<List<Serializable>> uploadFile(@RequestParam(value = "files", required = true) MultipartFile[] files , FileDto fileDto);


    /**
     *  获取文件 url
     * @param fileId
     * @return
     */
    @GetMapping("/file/fileUrl")
    Api<String> fileUrl(@RequestParam(value = "fileId")String fileId );


    /**
     * 删除
     * @param fileId
     * @return
     */
    @GetMapping("/file/delete")
    Api<String> delete(@RequestParam(value = "fileId")String fileId );

    /**
     * 下载
     * @param fileId
     * @param response
     * @return
     */
    @GetMapping("/file/download")
    Response download(@RequestParam(value = "fileId")String fileId , @RequestParam(value = "response") HttpServletResponse response);

}
